import { Router } from "express";
import { UserController } from "../controllers";
import { deserializeUser, requireLogin, validate } from "../middlewares";
import { updateUserSchema } from "../schemas";

const router = Router();

router.get("/me", deserializeUser, requireLogin, UserController.me);
router.get("/", UserController.findMany);
router.get("/:name", UserController.findOne);
router.patch(
  "/:name",
  validate(updateUserSchema),
  deserializeUser,
  requireLogin,
  UserController.update,
);
router.delete("/:name", deserializeUser, requireLogin, UserController.remove);
router.get("/:name/posts", UserController.findPosts);

export { router as userRouter };
